﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateWPOnRobotTCPF.CApCreateWpOnTCPFTCLogic
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.CreateWPOnRobotTCPF;

internal class CApCreateWpOnTCPFTCLogic : CApCreateWpTCLogic
{
  private CApCreateWpOnTCPFMgr _wpFactory = new CApCreateWpOnTCPFMgr();

  public static TxObjectList GetAvailableRobots()
  {
    return TxApplication.ActiveDocument.PhysicalRoot.GetAllDescendants((ITxTypeFilter) new TxTypeFilter(typeof (TxRobot)));
  }

  public bool IsDataValid(
    ITxObject robot,
    string wpName,
    ITxObject weldContainer,
    ITxObject weldOperation)
  {
    bool flag = false;
    if (robot != null && wpName.Length > 0 && this.IsDataValid(weldContainer, weldOperation))
      flag = true;
    return flag;
  }

  public void Accept(
    ITxObject obj,
    string wpName,
    ITxObject weldOperation,
    ITxObject weldContainer)
  {
    switch (obj)
    {
      case TxRobot _:
        this._wpFactory.CreateWpOnRobotTCPF(obj as TxRobot, wpName, weldContainer as TxCompoundPart, weldOperation as ITxWeldOperation);
        break;
      case ITxTool _:
        this._wpFactory.CreateWpOnRobotTCPF(obj as ITxTool, wpName, weldContainer as TxCompoundPart, weldOperation as ITxWeldOperation);
        break;
    }
  }

  public ITxObject GetSelectedRobot()
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxRobot));
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter);
    return ((Collection<ITxObject>) filteredItems).Count <= 0 ? (ITxObject) null : ((Collection<ITxObject>) filteredItems)[0];
  }

  public ITxRobot GetRobotFromOperation(ITxObject weldOperation)
  {
    ITxRobot robotFromOperation = (ITxRobot) null;
    if (weldOperation != null && weldOperation is ITxWeldOperation)
      robotFromOperation = ((ITxRoboticOrderedCompoundOperation) (weldOperation as ITxWeldOperation)).Robot;
    return robotFromOperation;
  }
}
